package cn.wolfcode.p2p.business.service.impl;
import java.util.Date;

import cn.wolfcode.p2p.business.domain.SystemAccount;
import cn.wolfcode.p2p.business.domain.SystemAccountFlow;
import cn.wolfcode.p2p.business.mapper.SystemAccountFlowMapper;
import cn.wolfcode.p2p.business.service.ISystemAccountFlowService;
import cn.wolfcode.p2p.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
@Transactional
public class SystemAccountFlowServiceImpl implements ISystemAccountFlowService {

    @Autowired
    private SystemAccountFlowMapper systemAccountFlowMapper;



    /**
     * 创建系统账户流水模板
     */
    public void createBaseFlow(SystemAccount systemAccount, BigDecimal amount, int actionType, String note) {
        SystemAccountFlow systemAccountFlow = new SystemAccountFlow();
        systemAccountFlow.setActionTime(new Date());
        systemAccountFlow.setActionType(actionType);
        systemAccountFlow.setAmount(amount);
        systemAccountFlow.setNote(note);
        systemAccountFlow.setUsableAmount(systemAccount.getUsableAmount());
        systemAccountFlow.setFreezedAmount(systemAccount.getFreezedAmount());
        systemAccountFlowMapper.insert(systemAccountFlow);
    }


    @Override
    public void createReceiveAccountManagementChargeFlow(SystemAccount systemAccount, BigDecimal accountManagementCharge, String title) {
       createBaseFlow(systemAccount,accountManagementCharge,Constants.SYSTEM_ACCOUNT_ACTIONTYPE_MANAGE_CHARGE,
               "收取借款手续费"+title);
    }

    @Override
    public void createReceiveInterestChargeFlow(SystemAccount systemAccount, BigDecimal interestManagerCharge) {
        createBaseFlow(systemAccount,interestManagerCharge,Constants.SYSTEM_ACCOUNT_ACTIONTYPE_INTREST_MANAGE_CHARGE,"收取利息管理费");
    }
}
